package com.atguigu.gmall.product.controller.admin;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * spu销售属性Controller层接口
 */
@RestController
@RequestMapping("/admin/product")
public class SpuSaleAttrController {

    @Autowired
    private SpuSaleAttrService spuSaleAttrService;

    /**
     * 根据spuId查询数据
     * @param spuId
     * @return
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable("spuId") Long spuId){
        //校验参数
        if(spuId == null){
            throw new GmallException("参数错误！",null);
        }

        //2 调用业务层方法
        List<SpuSaleAttr> spuSaleAttrList = spuSaleAttrService.listBySpuId(spuId);

        //3 响应数据
        return Result.ok(spuSaleAttrList);
    }

}
